var allcoupon;
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    couponlist: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var cptype = '1';
    if (options.cptype) {
      cptype = options.cptype;
    }
    this.setData({
      cptype: cptype
    });
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        var iconhgt = (res.windowWidth - 20) * 252 / 681;
        that.setData({
          iconhgt: iconhgt
        });
      },
    });
  },
  loadCouponlist:function(){
    var url = '/yuanmai_we/activity/getpromotion/list';
    app.loadDataFromServer(url,this.loadCouponlistCallBack,{},'get',true);
  },
  loadCouponlistCallBack:function(res){
    console.log(res);
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    allcoupon = {
      1: [
        {
          name: '骑士券',
          money: '10',
          starttime: '2017.02.27',
          endtime: '2017.03.31',
          type: 'online',
          tips: '限原麦山丘线上网购',
          condition: '满88元可用'
        }
      ],
      2: [
        {
          name: '骑士券',
          money: '20',
          starttime: '2017.02.27',
          endtime: '2017.03.31',
          type: 'door',
          tips: '限原麦山丘门店使用',
          condition: '满138元可用'
        }
      ],
      3: [
        {
          name: '骑士券',
          money: '20',
          starttime: '2017.02.27',
          endtime: '2017.03.31',
          type: 'door',
          tips: '限原麦山丘门店使用',
          condition: '满138元可用'
        },
        {
          name: '骑士券',
          money: '10',
          starttime: '2017.02.27',
          endtime: '2017.03.31',
          type: 'online',
          tips: '限原麦山丘线上网购',
          condition: '满88元可用'
        }
      ],
      4: []
    };
    this.setData({
      couponlist: allcoupon[1]
    });
    this.loadCouponlist();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  changeCouponType: function (e) {
    var cptype = e.currentTarget.id;
    if (cptype == this.data.cptype) {
      return;
    }
    this.setData({
      cptype: cptype,
      couponlist: allcoupon[cptype]
    });
  }
})